Skip to content

Combine repeated Accept-Encoding header lines when negotiating compression - #1090

Closed
BahaaMattar wants to merge 1 commit into
connectrpc:mainfrom
BahaaMattar:fix/accept-encoding-repeated-lines
Closed

BahaaMattar wants to merge 1 commit into
connectrpc:mainfrom
BahaaMattar:fix/accept-encoding-repeated-lines

Conversation

@BahaaMattar

Copy link
Copy Markdown

Fixes #1089

Handlers chose the response compression from only the first value of
Accept-Encoding (unary Connect), Connect-Accept-Encoding (streaming Connect)
and Grpc-Accept-Encoding (gRPC and gRPC-Web). If a client lists the encodings
it accepts on separate header lines, for example Accept-Encoding: br and
then Accept-Encoding: gzip, the handler only saw br, found no match and
sent the response uncompressed even though it supports gzip. RFC 9110 section
5.3 says several lines with the same name are equivalent to one
comma-separated line.

This adds getHeaderCanonicalJoined, which joins the values with a comma, and
uses it for the three accept-encoding lookups. A single header line is
returned as-is, so the common case is unchanged. The request's own
Content-Encoding is still read as a single value.

Tests:

  • TestHandlerRepeatedAcceptEncoding sends br and gzip on two separate
    lines to a Connect unary, a Connect streaming and a gRPC handler and
    expects gzip for each. It fails on main for all three and passes with this
    change.
  • Test_getHeaderCanonicalJoined covers the helper (none, one, several
    values, and values that already contain commas).

…ssion

Handlers read only the first value of Accept-Encoding, Connect-Accept-Encoding
and Grpc-Accept-Encoding. A client that sent the encodings it accepts on
separate header lines, such as "br" and then "gzip", got an uncompressed
response even though the handler supports gzip. Several header lines with the
same name mean the same as one comma-separated line (RFC 9110 Section 5.3),
so join them before choosing the response encoding.

Fixes connectrpc#1089

Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
@timostamm

Copy link
Copy Markdown
Member

Thanks for the contribution! There are open questions on #1089 that may affect what the right fix is, so I'd like to settle those on the issue first. Closing for now. We can reopen once that's decided.

@timostamm timostamm closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handlers ignore all but the first Accept-Encoding header line

2 participants